package com.css.fxfzdzzh.modules.hypergraph.service.impl;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.css.fxfzdzzh.base.attachment.entity.AttachmentInfoEntity;
import com.css.fxfzdzzh.base.attachment.service.AttachmentInfoService;
import com.css.fxfzdzzh.base.dict.repository.DictItemRepository;
import com.css.fxfzdzzh.base.dict.repository.entity.DictItemEntity;
import com.css.fxfzdzzh.base.response.RestResponse;
import com.css.fxfzdzzh.modules.downloadLegend.entity.TemplateEntity;
import com.css.fxfzdzzh.modules.evaluate.VO.PolygonEvaluateResultVO;
import com.css.fxfzdzzh.modules.evaluate.service.SoftSoilService;
import com.css.fxfzdzzh.modules.hypergraph.service.HypergraphService;
import com.css.fxfzdzzh.util.PlatformObjectUtils;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.*;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: fxfzdzzh
 * @Author: lhl
 * @CreateDate: 2023/6/5 14:23
 * 超图
 */
@Service
public class HypergraphServiceImpl implements HypergraphService {

    @Value("${hypergraph.iServerHttp}")
    String iServerHttp;
    @Value("${hypergraph.userName}")
    String userName;
    @Value("${hypergraph.password}")
    String password;

    //    @Resource
//    RestTemplate restTemplate;
    RestTemplate restTemplate = getRestTemplate();

    @Value("${hypergraph.filePath}")
    String filePath;
    @Value("${hypergraph.mapsPath}")
    String mapsPath;

    @Autowired
    DictItemRepository dictItemRepository;

    @Resource
    JdbcTemplate jdbcTemplate;

    @Resource
    private SoftSoilService softSoilService;

    @Resource
    AttachmentInfoService attachmentInfoService;

    /**
     * 调度器使用的RestTemplate，超时6000s
     *
     * @return
     */
    @Override
    public RestTemplate getRestTemplate() {
        RestTemplate restTemplate = new RestTemplateBuilder()
                .setConnectTimeout(Duration.ofSeconds(6000))
                .setReadTimeout(Duration.ofSeconds(6000))
                .build();
        //解决中文乱码
        List<HttpMessageConverter<?>> msgConv = restTemplate.getMessageConverters();
        if (msgConv != null && !msgConv.isEmpty()) {
            for (int i = 0; i < msgConv.size(); i++) {
                if (msgConv.get(i).getClass().equals(StringHttpMessageConverter.class)) {
                    msgConv.set(i, new StringHttpMessageConverter(StandardCharsets.UTF_8));
                }
            }
        }
        return restTemplate;
    }

    /**
     * @param map layerName:
     *            type://类型
     *            tif//高程
     *            filePath:
     *            slopeTif//坡度
     *            teraName:
     *            filePath:
     *            aspectTif//坡向
     *            teraName:
     *            filePath:
     *            clipTif//栅格裁剪文件
     *            geomText:
     *            resultLayerName:
     *            filePath:
     *            countTif//栅格自定义计算发布
     *            countString:
     *            countTif2//栅格自定义计算
     *            countString:
     *            countMapsTif//栅格自定义计算图层模板
     *            mapsName:
     *            countString:
     *            maxMinTif//栅格基本统计-获取最大最小值
     *            vectorTif-1//矢量转栅格的数据集 vectorTif-2//与基础数据的矢量转栅格的数据集
     *            clipLayerName:
     *            fieldName:
     *            sqlFilter:
     *            sqlFilterClip:
     *            exportTif//tif发布超图服务工具--创建任务（导出tif文件）
     *            demHslCount//tif发布超图服务工具--创建任务（DEM高程计算汇水量a）
     *            batchDelTif //tif发布超图服务工具--批量删除栅格数据集
     *            WorkspaceReload//刷新指定超图工作空间数据源数据集
     *            datasource:
     *            dataset:
     *            demCdlbCount//tif发布超图服务工具--创建任务（DEM高程计算场地类别）
     * @return
     */
    @Override
    public RestResponse getServerToken(Map<String, Object> map) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/security/tokens.rjson";
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("userName", userName);
            jsonObject.put("password", password);
            jsonObject.put("clientType", "NONE");//查询数量
            jsonObject.put("expiration", 120);//申请令牌的有效期，从发布令牌的时间开始计算，单位为分钟

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");
            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<String> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, String.class);
            String token = exchange.getBody();

            String type = (String) map.get("type");
            String layerName = (String) map.get("layerName");
            if (type.equals("tif")) {
                String filePath = (String) map.get("filePath");
                //tif发布超图服务工具--创建任务（tif发布）
                restResponse = tifMapLayerToolJobPost(layerName, filePath, token);
            } else if (type.equals("importSlopeTif")) {
                String filePath = (String) map.get("filePath");
                //tif发布超图服务工具--创建任务（导入坡度文件发布）
                restResponse = tifMapLayerToolJobPostPd(layerName, filePath, token);
            } else if (type.equals("importAspectTif")) {
                String filePath = (String) map.get("filePath");
                //tif发布超图服务工具--创建任务（导入坡向文件发布）
                restResponse = tifMapLayerToolJobPostPx(layerName, filePath, token);
            } else if (type.equals("slopeTif")) {
                String teraName = (String) map.get("teraName");
                String filePath = (String) map.get("filePath");
                //tif发布超图服务工具--创建任务（生成坡度）
                restResponse = tifMapLayerToolJobPost2(teraName, layerName, filePath, token);
            } else if (type.equals("aspectTif")) {
                String teraName = (String) map.get("teraName");
                String filePath = (String) map.get("filePath");
                //tif发布超图服务工具--创建任务（生成坡向）
                restResponse = tifMapLayerToolJobPost3(teraName, layerName, filePath, token);
            } else if (type.equals("clipTif")) {
                String resultLayerName = (String) map.get("resultLayerName");//裁剪结果数据集
                if (PlatformObjectUtils.isEmpty(resultLayerName)) {
                    String currTime = System.currentTimeMillis() + "";
                    resultLayerName = "temp_裁剪_" + currTime;//裁剪结果数据集
                }
                String geomText = (String) map.get("geomText");
                String sourceType = (String) map.get("sourceType");//数据源：dzzhTifCount、dzzhTifFile、jcsjTifFile
                //tif发布超图服务工具--创建任务（栅格裁剪文件发布）
                restResponse = tifMapLayerToolJobPost4(layerName, resultLayerName, filePath, sourceType, exchange.getBody(), geomText);
            } else if (type.equals("clipTif2")) {
                String resultLayerName = (String) map.get("resultLayerName");//裁剪结果数据集
                if (PlatformObjectUtils.isEmpty(resultLayerName)) {
                    String currTime = System.currentTimeMillis() + "";
                    resultLayerName = "temp_裁剪_" + currTime;//裁剪结果数据集
                }
                //任务范围的经纬度数据
                String geomText = (String) map.get("geomText");
                String sourceType = (String) map.get("sourceType");//数据源：dzzhTifCount、dzzhTifFile、jcsjTifFile
                //tif发布超图服务工具--创建任务（栅格裁剪）
                restResponse = tifMapLayerToolJobPost4_1(layerName, resultLayerName, filePath, sourceType, exchange.getBody(), geomText);
            } else if (type.equals("countTif")) {
                String countString = (String) map.get("countString");
                //tif发布超图服务工具--创建任务（栅格自定义计算发布）
                restResponse = tifMapLayerToolJobPost5(layerName, countString, token);
            } else if (type.equals("countMapsTif")) {
                String countString = (String) map.get("countString");
                String mapsName = (String) map.get("mapsName");
                //tif发布超图服务工具--创建任务（栅格自定义计算发布）
                restResponse = tifMapLayerToolJobPost5_2(layerName, mapsName, countString, token);
            } else if (type.equals("countMapsTif1")) {
                String countString = (String) map.get("countString");
                String mapsName = (String) map.get("mapsName");
                //tif发布超图服务工具--创建任务（栅格自定义计算发布）
                restResponse = tifMapLayerToolJobPost5_21(layerName, mapsName, token);
            } else if (type.equals("countTif2")) {
                String countString = (String) map.get("countString");
                //tif发布超图服务工具--创建任务（栅格自定义计算发布）
                restResponse = tifMapLayerToolJobPost5_3(layerName, countString, token);
            } else if (type.equals("countTif3")) {
                String countString = (String) map.get("countString");
                restResponse = tifMapLayerToolJobPost5_4(layerName, countString, token);
            } else if (type.equals("coypTif1")) {
                restResponse = tifMapLayerToolJobPost5_5(layerName, token);
            } else if (type.equals("coypTif2")) {
                restResponse = tifMapLayerToolJobPost5_6(layerName, token);
            } else if (type.equals("maxMinTif")) {
                //tif发布超图服务工具--同步执行处理自动化工具（栅格基本统计-获取最大最小值）
                restResponse = tifMapLayerToolJobGet1(layerName, token);
            } else if (type.contains("vectorTif")) {
                String clipLayerName = "";
                if (PlatformObjectUtils.isNotEmpty(map.get("clipLayerName"))) {
                    clipLayerName = (String) map.get("clipLayerName");
                }
                //边界数据集
                String timeStamp = System.currentTimeMillis() + "";//时间戳，用于数据集名称后缀，防止重名
                String resultLayerName = "temp_" + layerName + "_栅格_" + timeStamp;//裁剪结果数据集
                //裁剪结果数据集保存的路径
                String fieldName = (String) map.get("fieldName");
                //用于生成栅格值的矢量数据的字段，默认用超图自身的字段SmUserID值为0
                //矢量数据
                String datasetName = layerName;//用于转换栅格的矢量数据集名称
                String tempDatasetName = "temp_" + datasetName + "_" + timeStamp;//矢量过滤临时结果数据集名称
                String tempDzzhTaskName = "temp_dzzh_task_" + timeStamp;//矢量过滤临时结果数据集名称
                //过滤查询数据的表达式，即只保留符合sql条件的数据
                String sqlFilter = (String) map.get("sqlFilter");

                //边界裁剪
                String datasetNameClip = clipLayerName;//用于转换栅格的边界矢量数据集名称
                String tempDatasetNameClip = "temp_" + datasetNameClip + "_clip_" + timeStamp;//边界矢量过滤临时结果数据集名称
                //边界过滤查询数据的表达式，即只保留符合sql条件的数据
                String sqlFilterClip = (String) map.get("sqlFilterClip");
                //tif发布超图服务工具--创建任务（矢量过滤转换栅格发布）
                //fxfzdzzh、datacenter系统矢量过滤查询到dzzhTifCount
                //tif发布超图服务工具--矢量过滤查询
                String queryType = "fxfzdzzh";//查询类型：fxfzypg、fxfzdzzh、datacenter
                if ("vectorTif-1".equals(type)) {//dzzh系统数据，边界dzzh系统任务
                    queryType = "fxfzdzzh";
                } else if ("vectorTif-2".equals(type)) {//datacenter系统数据，边界dzzh系统任务
                    queryType = "datacenter";
                } else if ("vectorTif-3".equals(type)) {
                    restResponse = tifMapLayerToolJobPost15("dzzh_task", tempDzzhTaskName, sqlFilterClip, queryType, token);
                    if (restResponse.getCode() != 200) {
                        return restResponse;
                    }
                    clipLayerName = tempDzzhTaskName;
                }
                //String 矢量数据集名称，String_1 结果数据集名，String_2 SQL查询表达式
                restResponse = tifMapLayerToolJobPost15(layerName, tempDatasetName, sqlFilter, queryType, token);
                if (restResponse.getCode() != 200) {
                    return restResponse;
                }
                //ypgTifCount矢量栅格化
                //tif发布超图服务工具--矢量转换栅格ypg
                //String 矢量数据集名称 String_1 边界矢量数据集名称 String_2 字段名称 String_3 结果数据集名称
                restResponse = tifMapLayerToolJobPost16(tempDatasetName, clipLayerName, fieldName, resultLayerName, token);
            } else if (type.equals("exportTif")) {
                //tif发布超图服务工具--创建任务（导出tif文件）
                restResponse = tifMapLayerToolJobPost7(layerName, token);
            } else if (type == "demHslCount") {
                //tif发布超图服务工具--创建任务（DEM高程计算汇水量a）
                String timeStamp = System.currentTimeMillis() + "";//时间戳，用于数据集名称后缀，防止重名
//                计算综合地形指数步骤：
//                1.栅格投影3857--高程投影3857
//                2.dem高程计算汇水量a--地形、坡度、流向、汇水量
//                3.栅格计算--计算SCA（汇流累积量数据计算单位面积的汇流量）
//                栅格计算表达式：Con([dzzhTifCount.temp_汇水量_1710925376927]==0,1,[dzzhTifCount.temp_汇水量_1710925376927])*8100/Con([dzzhTifCount.temp_流向_1710925376927]==1,90,Con([dzzhTifCount.temp_流向_1710925376927]==4,90,Con([dzzhTifCount.temp_流向_1710925376927]==16,90,90*sqrt(2))))
//                4.栅格计算投影转换发布图层模板--计算综合地形指数TWI
//                栅格计算表达式：Ln([dzzhTifCount.temp_SCA_1710925376927]/Tan(Con([dzzhTifCount.temp_坡度_1710925376927]<=0,0.00001,[dzzhTifCount.temp_坡度_1710925376927])))
                //栅格投影
                String layerName2 = "temp_高程投影3857_" + timeStamp;
                restResponse = tifMapLayerToolJobPost8_1(layerName, layerName2, "3857", token);
                if (restResponse.getCode() != 200) {
                    return restResponse;
                }
                //高程计算地形、坡度、流向、汇水量
                restResponse = tifMapLayerToolJobPost8(layerName2, timeStamp, token);
                if (restResponse.getCode() != 200) {
                    return restResponse;
                }
                //流向
                String lxLayerName = JSON.parseObject(JSON.toJSONString(restResponse.getData())).getString("lx");
                //坡度
                String pdLayerName = JSON.parseObject(JSON.toJSONString(restResponse.getData())).getString("pd");
                //汇水量
                String hslLayerName = JSON.parseObject(JSON.toJSONString(restResponse.getData())).getString("hsl");
                //根据数据集名获取数据服务详情datasetInfo
                restResponse = getDatasetInfoByDataset(hslLayerName);
                if (restResponse.getCode() != 200) {
                    return restResponse;
                }
                JSONObject datasetInfo = (JSONObject) restResponse.getData();
                JSONObject bounds = datasetInfo.getJSONObject("bounds");
                double top = bounds.getDouble("top");
                double bottom = bounds.getDouble("bottom");
                double left = bounds.getDouble("left");
                double right = bounds.getDouble("right");
                double width = datasetInfo.getDouble("width");
                double height = datasetInfo.getDouble("height");
                //四舍五入保留2位小数
                //栅格长度（米）
                double xMeter = Math.round(((right-left)/width)*100.0)/100.0;
                //栅格宽度（米）
                double yMeter = Math.round(((top-bottom)/height)*100.0)/100.0;
                //计算栅格斜边（米）
                double guess = Math.round((Math.sqrt(xMeter*xMeter+yMeter*yMeter))*100.0)/100.0;
                //栅格计算SCA
                String scaLayerName = "temp_SCA_" + timeStamp;
                String countString = "Con([dzzhTifCount." + hslLayerName + "]==0,1,[dzzhTifCount." + hslLayerName + "])*8100/" +
                        "Con([dzzhTifCount." + lxLayerName + "]==1," + xMeter + "," +
                        "Con([dzzhTifCount." + lxLayerName + "]==4," + xMeter + "," +
                        "Con([dzzhTifCount." + lxLayerName + "]==16," + xMeter + "," + guess + ")))";
                restResponse = tifMapLayerToolJobPost5_3(scaLayerName, countString, token);
                if (restResponse.getCode() != 200) {
                    return restResponse;
                }
                //计算综合地形指数--栅格计算投影4490发布图层模板
                String countString2 = "Ln([dzzhTifCount." + scaLayerName + "]/Tan(Con([dzzhTifCount." + pdLayerName + "]<=0,0.00001,[dzzhTifCount." + pdLayerName + "])))";
                String resultLayerName = "temp_综合地形指数_" + timeStamp;
                String resultLayerName2 = "final_综合地形指数_" + timeStamp;
                restResponse = tifMapLayerToolJobPost8_2(countString2, resultLayerName, resultLayerName2, token);

            } else if (type == "demCdlbCount") {
                //tif发布超图服务工具--创建任务（DEM高程计算场地类别）
                String timeStamp = System.currentTimeMillis() + "";//时间戳，用于数据集名称后缀，防止重名
                String flag = (String) map.get("flag");
                String sql = "";
                String layerName2 = "temp_百分比_坡度_" + timeStamp;
                //通过坡度百分比计算场地类别sql
                if ("1".equals(flag)) {
                    //活动构造区
                    sql = "Con([dzzhTifCount." + layerName2 + "]==-9999,-9999," +
                            "Con([dzzhTifCount." + layerName2 + "]<0.01,0," +
                            "Con([dzzhTifCount." + layerName2 + "]<1.8,0.751," +
                            "Con([dzzhTifCount." + layerName2 + "]<13.8,0.178,0.070))))";
                } else if ("2".equals(flag)) {
                    //稳定大陆区
                    sql = "Con([dzzhTifCount." + layerName2 + "]==-9999,-9999," +
                            "Con([dzzhTifCount." + layerName2 + "]<0.002,0," +
                            "Con([dzzhTifCount." + layerName2 + "]<0.72,0.751," +
                            "Con([dzzhTifCount." + layerName2 + "]<2.5,0.178,0.070))))";
                }
                restResponse = tifMapLayerToolJobPost9(layerName, timeStamp, exchange.getBody(), sql, flag);
            } else if (type.equals("reclassify")) {
                //tif发布超图服务工具--创建任务（重分类自然分割法发布）
                String timeStamp = System.currentTimeMillis() + "";//时间戳，用于数据集名称后缀，防止重名
                restResponse = tifMapLayerToolJobPost10(layerName, timeStamp, token);
            } else if (type.equals("batchDelTif")) {
                String layerType = "栅格";
                //tif发布超图服务工具--批量删除栅格数据集
                restResponse = tifMapLayerToolJobPost11(layerName, layerType, token);
            } else if (type.equals("batchDelByLayerType")) {
                String layerType = (String) map.get("layerType");
                //tif发布超图服务工具--批量删除栅格数据集
                restResponse = tifMapLayerToolJobPost11(layerName, layerType, token);
            } else if (type.equals("gridFusion")) {
                //tif发布超图服务工具--全部栅格值矢量化融合
                String resultLayerName1 = (String) map.get("resultLayerName1");//矢量化结果数据集名
                String resultLayerName2 = (String) map.get("resultLayerName2");//结果数据集名
                //String 栅格数据集名称；String_1  矢量化结果数据集名；String_2 结果数据集名
                restResponse = tifMapLayerToolJobPost12(layerName, resultLayerName1, resultLayerName2, token);
            } else if (type.equals("gridVector")) {
                //tif发布超图服务工具--全部栅格值矢量化
                String resultLayerName1 = (String) map.get("resultLayerName1");//矢量化结果数据集名
                //String 栅格数据集名称；String_1  矢量化结果数据集名；String_2 结果数据集名
                restResponse = tifMapLayerToolJobPost12_1(layerName, resultLayerName1, token);
            } else if (type.equals("vectorQuery")) {
                //tif发布超图服务工具--矢量过滤查询
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                String sqlFilter = (String) map.get("sqlFilter");//SQL查询表达式
                //String 矢量数据集名称，String_1 结果数据集名，String_2 SQL查询表达式
                restResponse = tifMapLayerToolJobPost13(layerName, resultLayerName, sqlFilter, token);
            } else if (type.equals("dzzhIntersects")) {
                //tif发布超图服务工具--dzzh求交面积
                String resultLayerName1 = (String) map.get("resultLayerName1");//叠加数据集名
                String resultLayerName2 = (String) map.get("resultLayerName2");//结果数据集名
                //String 源矢量数据集名，String_1 叠加数据集名，String_2 结果数据集名
                restResponse = tifMapLayerToolJobPost14(layerName, resultLayerName1, resultLayerName2, token);
            } else if (type.equals("dzzhVectorQuery")) {//查询数据库矢量数据到dzzhTifCount
                //tif发布超图服务工具--dzzh查询数据库
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                String sqlFilter = (String) map.get("sqlFilter");//SQL查询表达式
                String queryType = (String) map.get("queryType");//查询数据库类型：fxfzdzzh、datacenter
                //String 矢量数据集名，String_1 结果数据集名，String_2 sql查询语句
                restResponse = tifMapLayerToolJobPost15(layerName, resultLayerName, sqlFilter, queryType, token);
            } else if (type.equals("dzzhCountVectorTif")) {
                //tif发布超图服务工具--矢量转换栅格dzzh
                String clipLayerName = (String) map.get("clipLayerName");//裁剪边界数据集名
                String fieldName = (String) map.get("fieldName");//字段名称
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                //String 矢量数据集名称 String_1 边界矢量数据集名称 String_2 字段名称 String_3 结果数据集名称
                restResponse = tifMapLayerToolJobPost16(layerName, clipLayerName, fieldName, resultLayerName, token);
            } else if (type.equals("dzzhVectorQuerySoftSoil")) {
                //tif发布超图服务工具--dzzh查询数据库软土震陷
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                String sqlFilter = (String) map.get("sqlFilter");//SQL查询表达式
                String layerName1 = (String) map.get("layerName1");
                String resultLayerName1 = (String) map.get("resultLayerName1");//结果数据集名
                String sqlFilter1 = (String) map.get("sqlFilter1");//SQL查询表达式
                //String 源矢量数据集名，String_1 结果数据集名称，String_2 SQL语句 String_3 源矢量数据集名1，String_4 结果数据集名称1，String_5 SQL语句1
                restResponse = tifMapLayerToolJobPost17(layerName, resultLayerName, sqlFilter, layerName1, resultLayerName1, sqlFilter1, token);
            } else if (type.equals("dzzhVectorToGridPolygon")) {//点数据集栅格克吕金插值分析提取等值面发布
                //tif发布超图服务工具--点数据集生成等值面发布软土震陷
                String queryType = (String) map.get("queryType");//查询类型：软土震陷、标贯法砂土液化、液化指数法砂土液化
                String fieldName = (String) map.get("fieldName");//字段名称
                String gridLayerName = (String) map.get("gridLayerName");//栅格数据集名
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                //String 点数据集名称 String_1 字段名称 String_2 栅格数据集名称 String_3 结果数据集名称
                restResponse = tifMapLayerToolJobPost18(queryType, layerName, fieldName, gridLayerName, resultLayerName, token);
            } else if (type.equals("dzzhVectorBufferTif")) {//断层、水系、道路生成多重缓冲区并转换栅格数据归一化赋值
                //tif发布超图服务工具--dzzh任务区域断层|水系|道路多重缓冲区栅格计算
                String queryType = (String) map.get("queryType");//查询类型：断层、水系、道路
                String timeStamp = (String) map.get("timeStamp");//时间戳
                //String 点数据集名称 String_1 字段名称 String_2 栅格数据集名称 String_3 结果数据集名称
                restResponse = tifMapLayerToolJobPost19(queryType, layerName, timeStamp, token);
            } else if (type.equals("waterVectorBufferTif")) {//砂土液化层次分析河流分级栅格计算
                //tif发布超图服务工具--dzzh砂土任务区域水系多重缓冲区栅格计算
                List<BigDecimal> waterList = (List<BigDecimal>) map.get("waterList");//栅格计算表达式
                String timeStamp = (String) map.get("timeStamp");//时间戳
                //String 任务区域边界数据集名 String_1 矢量数据集名 String_2 裁剪结果数据集名 String_3 缓冲区矢量数据集名
                //String_4 缓冲区栅格数据集名 String_5 栅格计算表达式 String_6 结果数据集名
                restResponse = tifMapLayerToolJobPost19_1(waterList, layerName, timeStamp, token);
            } else if (type.equals("投影3857重采样90米")) {//栅格投影3857重采样90米
                //tif发布超图服务工具--栅格投影重采样
                String resultLayerName1 = (String) map.get("resultLayerName1");//投影栅格数据集
                String resultLayerName2 = (String) map.get("resultLayerName2");//90米栅格数据集
                //String 栅格数据集名，String_1 投影栅格数据集，String_2 90米栅格数据集
                restResponse = tifMapLayerToolJobPost20(layerName, resultLayerName1, resultLayerName2, token);
            } else if (type.equals("栅格计算重分级")) {//栅格计算重分级
                //tif发布超图服务工具--栅格计算重分级
                String countString = (String) map.get("countString");//栅格计算表达式
                String resultLayerName = (String) map.get("resultLayerName");//计算结果数据集名称
                //String 栅格计算表达式，String_1 计算结果数据集名称
                restResponse = tifMapLayerToolJobPost21(countString, resultLayerName, token);
            } else if (type.equals("栅格区域统计")) {//栅格区域统计
                //tif发布超图服务工具--栅格计算重分级
                String districtLayerName = (String) map.get("districtLayerName");//区域数据集
                String resultLayerName = (String) map.get("resultLayerName");//结果栅格数据集
                String resultTableName = (String) map.get("resultTableName");//统计结果表
                //String 栅格数据集名，String_1 区域数据集，String_2 结果栅格数据集，String_3 统计结果表
                restResponse = tifMapLayerToolJobPost22(layerName, districtLayerName, resultLayerName, resultTableName, token);
            } else if (type.equals("矢量投影转换")) {//矢量投影转换
                //tif发布超图服务工具--矢量投影转换
                String resultLayerName = (String) map.get("resultLayerName");//投影矢量数据集
                //String 矢量数据集名，String_1 投影矢量数据集
                restResponse = tifMapLayerToolJobPost23(layerName, resultLayerName, token);
            } else if (type.equals("矢量过滤查询dzzhcount")) {//矢量过滤查询dzzhcount
                //tif发布超图服务工具--矢量过滤查询dzzhcount
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名称
                String sqlFilter = (String) map.get("sqlFilter");//SQL查询表达式
                //String 矢量数据集名，String_1 结果数据集名称，String_2 SQL查询表达式
                restResponse = tifMapLayerToolJobPost24(layerName, resultLayerName, sqlFilter, token);
            } else if (type.equals("区域制表统计栅格分级面积")) {//区域制表统计栅格分级面积
                //tif发布超图服务工具--区域制表统计栅格分级面积
                String districtLayerName = (String) map.get("districtLayerName");//行政区划数据集
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                //String 栅格数据集名，String_1 行政区划数据集，String_2 结果数据集名
                restResponse = tifMapLayerToolJobPost25(layerName, districtLayerName, resultLayerName, token);
            } else if (type.equals("getWebprintingLayoutsList")) {//获取Web打印出图模板列表
                //获取Web打印出图模板列表
                restResponse = supermapGetTemplateEntityList(map, token);
            } else if (type.equals("uploadTemplateFile")) {//上传模板文件到超图模板目录
                //上传模板文件到超图模板目录
                restResponse = supermapPostTemplateFile(map, token);
            } else if (type.equals("WorkspaceReload")) {
                String datasource = (String) map.get("datasource");//数据源
                String dataset = (String) map.get("dataset");//数据集
                //查询字典--超图数据源工作空间文件路径
                DictItemEntity dte = dictItemRepository.findOneByDictItemCodeAndDictId(datasource, "12");
                String smwuUrl = dte.getDictItemName();//工作空间文件路径
                //刷新指定超图工作空间数据源数据集
                restResponse = mapLayerWorkspaceReload(smwuUrl, datasource, dataset, token);
            } else if (type.equals("token")) {//获取超图服务token
                restResponse = RestResponse.succeed(token);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（生成高程）
    private RestResponse tifMapLayerToolJobPost(String layerName, String filePath, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:tif发布/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            if (PlatformObjectUtils.isEmpty(filePath)) {
                parameter.put("String", filePath + layerName + ".tif");//tif文件路径
            } else {
                parameter.put("String", filePath);//栅格裁剪结果文件路径
            }
            parameter.put("String_1", layerName);//栅格数据集名称
            parameter.put("String_2", layerName);//栅格图层名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（导入坡度）
    private RestResponse tifMapLayerToolJobPostPd(String layerName, String filePath, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:导入坡度文件发布/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            if (PlatformObjectUtils.isEmpty(filePath)) {
                parameter.put("String", filePath + layerName + ".tif");//tif文件路径
            } else {
                parameter.put("String", filePath);//栅格裁剪结果文件路径
            }
            parameter.put("String_1", layerName);//栅格数据集名称
            parameter.put("String_2", layerName);//栅格图层名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（导入坡向）
    private RestResponse tifMapLayerToolJobPostPx(String layerName, String filePath, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:导入坡向文件发布/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            if (PlatformObjectUtils.isEmpty(filePath)) {
                parameter.put("String", filePath + layerName + ".tif");//tif文件路径
            } else {
                parameter.put("String", filePath);//栅格裁剪结果文件路径
            }
            parameter.put("String_1", layerName);//栅格数据集名称
            parameter.put("String_2", layerName);//栅格图层名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（生成坡度）
    private RestResponse tifMapLayerToolJobPost2(String teraName, String layerName, String filePath, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:生成坡度/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", teraName);//高程数据集名称
            parameter.put("String_1", layerName);//坡度数据集名称
            if (PlatformObjectUtils.isEmpty(filePath)) {
                parameter.put("String_2", filePath + layerName + ".tif");
            } else {
                parameter.put("String_2", filePath);//栅格裁剪结果文件路径
            }
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（生成坡向）
    private RestResponse tifMapLayerToolJobPost3(String teraName, String layerName, String filePath, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:生成坡向/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", teraName);//高程数据集名称
            parameter.put("String_1", layerName);//坡向数据集名称
            if (PlatformObjectUtils.isEmpty(filePath)) {
                parameter.put("String_2", filePath + layerName + ".tif");
            } else {
                parameter.put("String_2", filePath);//栅格裁剪结果文件路径
            }
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //面wkt裁剪栅格文件发布（裁剪栅格数据集，然后导出文件并发布裁剪结果图层）
    private RestResponse tifMapLayerToolJobPost4(String layerName, String resultLayerName, String filePath, String sourceType, String serverToken, String geomText) {
        RestResponse restResponse = null;
        try {
            //数据源sourceType：dzzhTifCount
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:面wkt裁剪栅格文件发布/jobs?token=" + serverToken;
            if (sourceType.equals("dzzhTifFile")) {//地质灾害系统坡度、坡向文件
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:面wkt裁剪栅格文件发布dzzhfile/jobs?token=" + serverToken;
            } else if (sourceType.equals("jcsjTifFile")) {//基础数据系统高程文件
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:面wkt裁剪栅格文件发布基础数据/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("GeoRegion", geomText);//面几何对象wkt
            parameter.put("81d2403b-02b5-4735-978b-48724a006e82", layerName);//栅格数据集名称
            parameter.put("64df700f-7c1d-4ff0-8d74-2a5f8114e8e8", -9999);//栅格无值
            parameter.put("52868036-e093-4e1e-9662-db82d7e5b7ab", resultLayerName);//栅格裁剪结果数据集名称
            parameter.put("7cb39b22-8ee1-48d4-ba0c-9067576e1b10", filePath + resultLayerName + ".tif");//栅格裁剪结果文件路径

            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setData(filePath + resultLayerName + ".tif");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //面wkt裁剪栅格（只裁剪栅格数据集，不导出文件，不发布裁剪结果图层）
    private RestResponse tifMapLayerToolJobPost4_1(String layerName, String resultLayerName, String filePath, String sourceType, String serverToken, String geomText) {
        RestResponse restResponse = null;
        try {
            //数据源sourceType：dzzhTifCount
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:面wkt裁剪栅格/jobs?token=" + serverToken;
            if (sourceType.equals("dzzhTifCount")) {//地质灾害系统
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:面wkt裁剪栅格/jobs?token=" + serverToken;
            } else if (sourceType.equals("dzzhTifCount精确")) {//地质灾害系统精确裁剪
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:面wkt裁剪栅格精确/jobs?token=" + serverToken;
            } else if (sourceType.equals("dzzhTifFile")) {//地质灾害系统坡度、坡向文件
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:面wkt裁剪栅格dzzhfile/jobs?token=" + serverToken;
            } else if (sourceType.equals("jcsjTifFile")) {//基础数据系统高程文件
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:面wkt裁剪栅格基础数据/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("GeoRegion", geomText);//面几何对象wkt
            parameter.put("81d2403b-02b5-4735-978b-48724a006e82", layerName);//栅格数据集名称
            parameter.put("64df700f-7c1d-4ff0-8d74-2a5f8114e8e8", -9999);//栅格无值
            parameter.put("52868036-e093-4e1e-9662-db82d7e5b7ab", resultLayerName);//栅格裁剪结果数据集名称
            parameter.put("7cb39b22-8ee1-48d4-ba0c-9067576e1b10", filePath + resultLayerName + ".tif");//栅格裁剪结果文件路径

            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setData(filePath + resultLayerName + ".tif");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost5(String resultLayerName, String countString, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:栅格计算发布/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", countString);//栅格计算表达式
            parameter.put("String_1", resultLayerName);//计算结果数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setData(filePath + resultLayerName + ".tif");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost5_2(String resultLayerName, String mapsName, String countString
            , String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:栅格计算发布图层模板/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", countString);//栅格计算表达式
            parameter.put("String_1", resultLayerName);//计算结果数据集名称
            parameter.put("String_2", mapsPath + mapsName);//图层模板
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setData(filePath + resultLayerName + ".tif");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost5_21(String resultLayerName, String mapsName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh自动制图发布图层模板/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", resultLayerName);//计算结果数据集名称
            parameter.put("String_1", mapsPath + mapsName);//图层模板
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setData(filePath + resultLayerName + ".tif");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost5_3(String resultLayerName, String countString, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:栅格计算/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", countString);//栅格计算表达式
            parameter.put("String_1", resultLayerName);//计算结果数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost5_4(String resultLayerName, String countString, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:服务器栅格计算/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", countString);//栅格计算表达式
            parameter.put("String_1", resultLayerName);//计算结果数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost5_5(String resultLayerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh复制栅格数据集/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", resultLayerName);//复制的栅格数据集
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost5_6(String resultLayerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:结果复制栅格数据集dzzh/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", resultLayerName);//复制的栅格数据集
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }


    //tif发布超图服务工具--创建任务（矢量过滤转换栅格发布）
    private RestResponse tifMapLayerToolJobPost6(String datasetName,
                                                 String resultLayerName, String fieldName,
                                                 String tempDatasetName, String sqlFilter,
                                                 String tempDatasetNameClip, String datasetNameClip, String sqlFilterClip,
                                                 String serverToken, String type) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:矢量过滤转换栅格发布/jobs?token=" + serverToken;
            if ("vectorTif-2".equals(type)) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:矢量过滤转换栅格发布基础数据/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            String resultFilePath = filePath + resultLayerName + ".tif";
            Double size = 0.0008880937137850466;//单元格大小，即栅格分辨率，可通过读取原栅格数据的分辨率设置，需要将如8.880937137850466E-4的科学记数转成浮点数
            Double noDataValue = -9999d;//空白区域值，即设置无值
            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", resultLayerName);//结果数据集名称
            parameter.put("String_1", fieldName);//字段名称
            parameter.put("String_2", datasetName);//矢量数据集名称
            parameter.put("String_3", tempDatasetName);//目标数据集名称
            parameter.put("String_4", sqlFilter);//SQL删除过滤表达式
            parameter.put("String_5", datasetNameClip);//边界矢量数据集名称
            parameter.put("String_6", tempDatasetNameClip);//边界目标数据集名称
            parameter.put("String_7", sqlFilterClip);//边界SQL删除过滤表达式
            parameter.put("String_8", resultFilePath);//导出文件路径
            parameter.put("Double", size);//栅格分辨率
            parameter.put("Double_1", noDataValue);//空白区域值
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                jsonObject1.put("resultFilePath", resultFilePath);
                restResponse.setData(jsonObject1);
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    // tif发布超图服务工具--创建任务（导出tif文件）
    private RestResponse tifMapLayerToolJobPost7(String layerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:导出tif文件/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            String resultFilePath = filePath + layerName + ".tif";//导出文件路径
            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String_1", layerName);//数据集名称
            parameter.put("String_2", resultFilePath);//矢量数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", layerName);
                jsonObject1.put("resultFilePath", resultFilePath);
                restResponse.setData(jsonObject1);
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost8(String layerName, String timeStamp, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dem高程计算汇水量a/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            String layerName2 = "temp_流向_" + timeStamp;
            String layerName3 = "temp_坡度_" + timeStamp;
            String layerName4 = "temp_地形_" + timeStamp;
            String layerName5 = "temp_汇水量_" + timeStamp;//结果数据集名

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//高程数据集名称
            parameter.put("String_1", layerName2);//流向栅格数据集名
            parameter.put("String_2", layerName3);//坡度数据集名称
            parameter.put("String_3", layerName4);//地形数据集名
            parameter.put("String_4", layerName5);//结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("lx", layerName2);
                jsonObject1.put("pd", layerName3);
                jsonObject1.put("dx", layerName4);
                jsonObject1.put("hsl", layerName5);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //栅格投影
    private RestResponse tifMapLayerToolJobPost8_1(String layerName, String layerName2, String epsgType, String serverToken) {
        RestResponse restResponse = null;
        try {
            //投影EPSG:3857
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:栅格投影3857/jobs?token=" + serverToken;
            if (epsgType.equals("4490")) {//EPSG:4490
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:栅格投影4490/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名
            parameter.put("String_1", layerName2);//投影栅格数据集
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", layerName2);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //计算综合地形指数--栅格计算投影4490发布图层模板
    private RestResponse tifMapLayerToolJobPost8_2(String countString, String resultLayerName, String resultLayerName2, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:栅格计算投影4490发布图层模板/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", countString);//栅格计算表达式
            parameter.put("String_1", resultLayerName);//计算结果数据集名称
            parameter.put("String_3", resultLayerName2);//投影转换数据集名
            parameter.put("String_2", mapsPath + "砂土综合地形指数-图例.xml");//图层模板文件路径
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setData(filePath + resultLayerName2 + ".tif");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost9(String layerName, String timeStamp, String serverToken, String sql, String flag) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dem高程计算场地类别图层模板/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            String layerName2 = "temp_百分比_坡度_" + timeStamp;
            String layerName3 = "final_场地类别_" + ("1".equals(flag) ? "活动构造区_" : "稳定大陆区_") + timeStamp;//结果数据集名

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//高程数据集名称
            parameter.put("String_1", layerName2);//坡度数据集名称
            parameter.put("String_2", sql);//栅格计算表达式
            parameter.put("String_3", layerName3);//计算结果数据集名称
            if ("1".equals(flag)) {
                parameter.put("String_4", mapsPath + "砂土-层次-活动构造区-图例.xml");
            } else if ("2".equals(flag)) {
                parameter.put("String_4", mapsPath + "砂土-层次-稳定大陆区-图例.xml");
            }
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", layerName3);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost10(String layerName, String timeStamp, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:重分类自然分割法发布/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            String layerName2 = "final_重分类_自然分割_" + timeStamp;//结果数据集名
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名称
            parameter.put("Integer", 5);//区域数量
            parameter.put("Integer_1", 0);//最低区域的值
            parameter.put("String_1", layerName2);//计算结果数据集名称
            parameter.put("String_2", mapsPath + "砂土液化层次分析法-图例.xml");//计算结果数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", layerName2);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost11(String layerName, String layerType, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:批量删除栅格数据集/jobs?token=" + serverToken;
            if (layerType.equals("栅格")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:批量删除栅格数据集/jobs?token=" + serverToken;
            } else if (layerType.equals("矢量")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:批量删除矢量数据集/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setMessage("删除成功！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost12(String layerName, String resultLayerName1, String resultLayerName2,
                                                  String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:全部栅格值矢量化融合/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 栅格数据集名称；String_1  矢量化结果数据集名；String_2 结果数据集名
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名称
            parameter.put("String_1", resultLayerName1);//矢量化结果数据集名
            parameter.put("String_2", resultLayerName2);//结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName2);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost12_1(String layerName, String resultLayerName1, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:全部栅格值矢量化/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 栅格数据集名称；String_1  矢量化结果数据集名
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名称
            parameter.put("String_1", resultLayerName1);//矢量化结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName1);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost13(String layerName, String resultLayerName, String sql, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:矢量过滤查询/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 矢量数据集名称，String_1 结果数据集名称，String_2 SQL查询表达式
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名称
            parameter.put("String_1", resultLayerName);//结果数据集名称
            parameter.put("String_2", sql);//SQL查询表达式
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost14(String layerName, String resultLayerName1, String resultLayerName2,
                                                  String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh求交面积/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 源矢量数据集名，String_1 叠加数据集名，String_2 结果数据集名
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//源矢量数据集名
            parameter.put("String_1", resultLayerName1);//叠加数据集名
            parameter.put("String_2", resultLayerName2);//结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName2);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //查询数据库矢量数据到dzzhTifCount
    private RestResponse tifMapLayerToolJobPost15(String layerName, String resultLayerName, String sql, String queryType,
                                                  String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh查询数据库/jobs?token=" + serverToken;
            if (queryType.equals("fxfzdzzh")) {
                //数据库端SQL查询语句
                sql = "select * from " + layerName + " where " + sql;
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh查询数据库/jobs?token=" + serverToken;
            } else if (queryType.equals("datacenter")) {
                //数据库端SQL查询语句
                sql = "select * from " + layerName + " where " + sql;
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh查询数据库基础数据/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 源矢量数据集名，String_1 叠加数据集名，String_2 结果数据集名
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名称
            parameter.put("String_1", resultLayerName);//结果数据集名称
            parameter.put("String_2", sql);//SQL语句
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //矢量转换栅格dzzh
    private RestResponse tifMapLayerToolJobPost16(String layerName, String clipLayerName, String fieldName, String resultLayerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:矢量转换栅格dzzh/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名称
            parameter.put("String_1", clipLayerName);//边界矢量数据集名称
            parameter.put("String_2", fieldName);//字段名称
            parameter.put("String_3", resultLayerName);//结果数据集名称
            Double size = 0.0008880937137850466;//单元格大小，即栅格分辨率，可通过读取原栅格数据的分辨率设置，需要将如8.880937137850466E-4的科学记数转成浮点数
            Double noDataValue = -9999d;//空白区域值，即设置无值
            parameter.put("Double", size);//栅格分辨率
            parameter.put("Double_1", noDataValue);//空白区域值
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //dzzh查询数据库软土震陷
    private RestResponse tifMapLayerToolJobPost17(String layerName, String resultLayerName, String sqlFilter, String layerName1, String resultLayerName1, String sqlFilter1,
                                                  String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh查询数据库软土震陷/jobs?token=" + serverToken;
            //数据库端SQL查询语句
            sqlFilter = "select * from " + layerName + " where " + sqlFilter;
            sqlFilter1 = "select * from " + layerName1 + " where " + sqlFilter1;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 源矢量数据集名，String_1 结果数据集名称，String_2 SQL语句 String_3 源矢量数据集名1，String_4 结果数据集名称1，String_5 SQL语句1
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名称
            parameter.put("String_1", resultLayerName);//结果数据集名称
            parameter.put("String_2", sqlFilter);//SQL语句
            parameter.put("String_3", layerName1);//矢量数据集名称1
            parameter.put("String_4", resultLayerName1);//结果数据集名称1
            parameter.put("String_5", sqlFilter1);//SQL语句1
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //点数据集栅格克吕金插值分析提取等值面发布
    private RestResponse tifMapLayerToolJobPost18(String queryType, String layerName, String fieldName, String gridLayerName, String resultLayerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:点数据集栅格克吕金插值分析提取等值面发布/jobs?token=" + serverToken;
            if (queryType.equals("软土震陷")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:点数据集生成等值面发布软土震陷/jobs?token=" + serverToken;
            } else if (queryType.equals("标贯法砂土液化")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:点数据集生成等值面发布标贯法砂土液化/jobs?token=" + serverToken;
            } else if (queryType.equals("液化指数法砂土液化")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:点数据集生成等值面发布液化指数法砂土液化/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名称
            parameter.put("String_1", fieldName);//字段名称
            parameter.put("String_2", gridLayerName);//边界矢量数据集名称
            parameter.put("String_3", resultLayerName);//结果数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //断层、水系、道路生成多重缓冲区并转换栅格数据归一化赋值
    private RestResponse tifMapLayerToolJobPost19(String queryType, String taskLayerName, String timeStamp, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh任务区域断层多重缓冲区栅格计算/jobs?token=" + serverToken;
            String layerName = "jc_fault";
            if (queryType.equals("断层")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh任务区域断层多重缓冲区栅格计算/jobs?token=" + serverToken;
                layerName = "jc_fault";
            } else if (queryType.equals("水系")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh任务区域水系多重缓冲区栅格计算/jobs?token=" + serverToken;
                layerName = "jc_hydl";
            } else if (queryType.equals("道路")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh任务区域道路多重缓冲区栅格计算/jobs?token=" + serverToken;
                layerName = "jc_lrdl";
            } else if (queryType.equals("砂土水系")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh砂土任务区域水系多重缓冲区栅格计算/jobs?token=" + serverToken;
                layerName = "jc_hydl";
            }
            String layerClipName = "temp_" + layerName + "_" + timeStamp;
            String bufferLayerName = "temp_" + layerName + "_buffer_" + timeStamp;
            String gridLayerName = "temp_" + layerName + "_grid_" + timeStamp;
            String resultLayerName = "temp_" + layerName + "_result_" + timeStamp;
            String sqlString = "Con([dzzhTifCount." + gridLayerName + "]==-9999,0," +
                    "Con([dzzhTifCount." + gridLayerName + "]==1,1," +
                    "Con([dzzhTifCount." + gridLayerName + "]==2,0.67," +
                    "Con([dzzhTifCount." + gridLayerName + "]==3,0.33," +
                    "Con([dzzhTifCount." + gridLayerName + "]==4,0.11,0)))))";
            if (queryType.equals("砂土水系")){
                sqlString = "Con([dzzhTifCount." + gridLayerName + "]==-9999,0," +
                        "Con([dzzhTifCount." + gridLayerName + "]==1,0.472," +
                        "Con([dzzhTifCount." + gridLayerName + "]==2,0.292," +
                        "Con([dzzhTifCount." + gridLayerName + "]==3,0.122," +
                        "Con([dzzhTifCount." + gridLayerName + "]==4,0.075,0.039)))))";
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", taskLayerName);//任务区域边界数据集名
            parameter.put("String_1", layerName);//矢量数据集名
            parameter.put("String_2", layerClipName);//裁剪结果数据集名
            parameter.put("String_3", bufferLayerName);//缓冲区矢量数据集名
            parameter.put("String_4", gridLayerName);//缓冲区栅格数据集名
            parameter.put("String_5", sqlString);//栅格计算表达式
            parameter.put("String_6", resultLayerName);//结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //砂土液化层次分析河流分级栅格计算
    private RestResponse tifMapLayerToolJobPost19_1(List<BigDecimal> waterList, String taskLayerName, String timeStamp, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:dzzh砂土任务区域水系多重缓冲区栅格计算/jobs?token=" + serverToken;
            String layerName = "jc_hydl";
            String layerClipName = "temp_" + layerName + "_" + timeStamp;
            String bufferLayerName = "temp_" + layerName + "_buffer_" + timeStamp;
            String gridLayerName = "temp_" + layerName + "_grid_" + timeStamp;
            String resultLayerName = "temp_" + layerName + "_result_" + timeStamp;
//            String countString = "Con([dzzhTifCount." + gridLayerName + "]==-9999,0," +
//                    "Con([dzzhTifCount." + gridLayerName + "]==1,0.472," +
//                    "Con([dzzhTifCount." + gridLayerName + "]==2,0.292," +
//                    "Con([dzzhTifCount." + gridLayerName + "]==3,0.122," +
//                    "Con([dzzhTifCount." + gridLayerName + "]==4,0.075,0.039)))))";
            String countString = "Con([dzzhTifCount." + gridLayerName + "]==-9999,0," +
                    "Con([dzzhTifCount." + gridLayerName + "]==1,"+waterList.get(0)+"," +
                    "Con([dzzhTifCount." + gridLayerName + "]==2,"+waterList.get(1)+"," +
                    "Con([dzzhTifCount." + gridLayerName + "]==3,"+waterList.get(2)+"," +
                    "Con([dzzhTifCount." + gridLayerName + "]==4,"+waterList.get(3)+","+waterList.get(4)+")))))";
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", taskLayerName);//任务区域边界数据集名
            parameter.put("String_1", layerName);//矢量数据集名
            parameter.put("String_2", layerClipName);//裁剪结果数据集名
            parameter.put("String_3", bufferLayerName);//缓冲区矢量数据集名
            parameter.put("String_4", gridLayerName);//缓冲区栅格数据集名
            parameter.put("String_5", countString);//栅格计算表达式
            parameter.put("String_6", resultLayerName);//结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //栅格投影重采样
    private RestResponse tifMapLayerToolJobPost20(String layerName, String resultLayerName1, String resultLayerName2, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:栅格投影重采样/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 栅格数据集名，String_1 投影栅格数据集，String_2 90米栅格数据集
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名
            parameter.put("String_1", resultLayerName1);//投影栅格数据集
            parameter.put("String_2", resultLayerName2);//90米栅格数据集
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName2);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //栅格计算重分级
    private RestResponse tifMapLayerToolJobPost21(String countString, String resultLayerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:栅格计算重分级/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 栅格计算表达式，String_1 计算结果数据集名称
            JSONObject parameter = new JSONObject();
            parameter.put("String", countString);//栅格计算表达式
            parameter.put("String_1", resultLayerName);//计算结果数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //栅格区域统计
    private RestResponse tifMapLayerToolJobPost22(String layerName, String districtLayerName, String resultLayerName, String resultTableName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:栅格区域统计/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 栅格数据集名，String_1 区域数据集，String_2 结果栅格数据集，String_3 统计结果表
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名
            parameter.put("String_1", districtLayerName);//区域数据集
            parameter.put("String_2", resultLayerName);//结果栅格数据集
            parameter.put("String_3", resultTableName);//统计结果表
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                jsonObject1.put("resultTableName", resultTableName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //矢量投影转换
    private RestResponse tifMapLayerToolJobPost23(String layerName, String resultLayerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:矢量投影转换/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 矢量数据集名，String_1 投影矢量数据集
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名
            parameter.put("String_1", resultLayerName);//投影矢量数据集
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //矢量过滤查询dzzhcount
    private RestResponse tifMapLayerToolJobPost24(String layerName, String resultLayerName, String sqlFilter, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:矢量过滤查询dzzhcount/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 矢量数据集名，String_1 结果数据集名称，String_2 SQL查询表达式
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名称
            parameter.put("String_1", resultLayerName);//结果数据集名称
            parameter.put("String_2", sqlFilter);//SQL查询表达式
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //区域制表统计栅格分级面积
    private RestResponse tifMapLayerToolJobPost25(String layerName, String districtLayerName, String resultLayerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:区域制表统计栅格分级面积/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 栅格数据集名，String_1 行政区划数据集，String_2 结果数据集名
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名
            parameter.put("String_1", districtLayerName);//行政区划数据集
            parameter.put("String_2", resultLayerName);//结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //根据数据集名获取数据服务详情datasetInfo
    @Override
    public RestResponse getDatasetInfoByDataset(String dataset) {
        JSONObject result = new JSONObject();
        try {
            String dataUrl = iServerHttp + "/iserver/services/data-dzzhTifCount/rest/data/datasources/dzzhTifCount/datasets/" + dataset + ".rjson";
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
            ResponseEntity<String> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, String.class);
            JSONObject body = JSON.parseObject(JSON.parseObject(JSON.toJSONString(exchange)).getString("body"));
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            result = body.getJSONObject("datasetInfo");
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return RestResponse.succeed(result);
    }

    //SQL查询超图图层数据
    @Override
    public RestResponse mapSqlQueryResultsPost(String layerUrl, String datasource, String dataset, String networkType, String sqlFilter) {
        RestResponse restResponse = null;
        try {
            String dataUrl = layerUrl + "/queryResults.json?returnContent=true";
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("queryMode", "SqlQuery");
            JSONObject queryParameters = new JSONObject();
            queryParameters.put("expectCount", 100000);
            queryParameters.put("networkType", networkType);//LINE、POINT、REGION
            queryParameters.put("queryOption", "ATTRIBUTEANDGEOMETRY");//查询结果类型枚举，描述查询结果返回类型，包括ATTRIBUTE 只返回属性、GEOMETRY 只返回几何实体、ATTRIBUTEANDGEOMETRY 返回属性和几何实体。
            JSONArray queryParams = new JSONArray();
            JSONObject params = new JSONObject();
            params.put("name", dataset + "@" + datasource);
            params.put("attributeFilter", sqlFilter);
            queryParams.add(params);
            queryParameters.put("queryParams", queryParams);
            jsonObject.put("queryParameters", queryParameters);
            System.out.println(jsonObject);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            int currentCount = body.getInteger("currentCount");
            int totalCount = body.getInteger("totalCount");
            if (currentCount > 0) {//返回结果
                JSONArray recordsets = body.getJSONArray("recordsets");
//            JSONArray features = body.getJSONArray("recordsets").getJSONObject(0).getJSONArray("features");
                JSONObject result = new JSONObject();
                result.put("currentCount", currentCount);
                result.put("totalCount", totalCount);
                result.put("recordsets", recordsets);
                restResponse = RestResponse.succeed(result);
            } else {
                return RestResponse.fail("无查询结果数据！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobGet1(String layerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布dzzh系统:栅格基本统计/execute?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            // JSONObject jsonObject = new JSONObject();
            Map<String, Object> params = new HashMap<>();
            params.put("String", layerName);//计算结果数据集名称
            // jsonObject.put("parameter", parameter);
            // JSONArray environment = new JSONArray();
            // jsonObject.put("environment", environment);
            String parameter = JSON.toJSONString(params);
            dataUrl = dataUrl + "&parameter={parameter}&environment=" + new JSONArray();

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
            ResponseEntity<String> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, String.class, parameter);
            JSONObject body = JSON.parseObject(JSON.parseObject(JSON.toJSONString(exchange)).getString("body"));
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            JSONObject jsonObject1 = JSON.parseObject(body.getString("basicstatistics-basicStatisticsAnalystResult"));
            if (jsonObject1 == null) {
                return RestResponse.fail("未获取到数据！");
            }
            JSONObject jsonObject2 = JSON.parseObject(jsonObject1.getString("basicStatisticsAnalystResult"));
            if (jsonObject2 == null) {
                return RestResponse.fail("未获取到数据！");
            }
            JSONObject jsonObject3 = new JSONObject();
            jsonObject3.put("max", jsonObject2.getBigDecimal("max"));
            jsonObject3.put("min", jsonObject2.getBigDecimal("min"));
            // restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            // if (restResponse.getCode()==200){
            //     restResponse.setData(filePath4 + layerName + ".tif");
            // }
            restResponse = RestResponse.succeed(jsonObject3);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }


    private RestResponse tifMapLayerToolJobGet(String jobID, String serverToken) {
        JSONObject result = new JSONObject();
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/jobs/" + jobID + ".json?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            /*if(body.containsKey("error")){
                return RestResponse.fail("未获取到数据！");
            }*/
            if (!body.getJSONObject("state").getBooleanValue("success")
                    && !body.getJSONObject("state").getString("runState").equals("RUNNING")) {
                return RestResponse.fail("未获取到数据！");
            }
            BigDecimal percent = body.getJSONObject("progress").getBigDecimal("percent");
            while (percent.compareTo(BigDecimal.valueOf(100)) < 0) {
                Thread.sleep(1000);
                //获取任务执行百分比
                percent = tifMapLayerToolJobGetPercent(jobID, serverToken);
                if (percent.compareTo(BigDecimal.valueOf(-1)) == 0) {
                    return RestResponse.fail("该任务未获取到数据！");
                }
            }
            result.put("result", "获取成功！");
        } catch (Exception e) {
            e.printStackTrace();
            if (e.getMessage().contains("无效的令牌")) {
                return RestResponse.fail("无效的令牌！");
            }
            return tifMapLayerToolJobGet(jobID, serverToken);
        }
        return RestResponse.succeed(result);
    }

    //获取任务执行百分比
    private BigDecimal tifMapLayerToolJobGetPercent(String jobID, String serverToken) {
        BigDecimal jobPercent = BigDecimal.ZERO;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/jobs/" + jobID + ".json?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return jobPercent;
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return jobPercent;
            }
            /*if(body.containsKey("error")){
                return BigDecimal.valueOf(-1);
            }*/
            if (!body.getJSONObject("state").getBooleanValue("success")
                    && !body.getJSONObject("state").getString("runState").equals("RUNNING")) {
                return BigDecimal.valueOf(-1);
            }
            BigDecimal percent = body.getJSONObject("progress").getBigDecimal("percent");
            if (percent.compareTo(BigDecimal.valueOf(100)) == 0) {
                if (body.getJSONObject("state").getString("runState").equals("RUNNING")) {//正在执行
                    percent = BigDecimal.valueOf(99);
                }
            }
            jobPercent = percent;
        } catch (Exception e) {
            e.printStackTrace();
            if (e.getMessage().contains("无效的令牌")) {
                return BigDecimal.valueOf(-1);
            }
            return jobPercent;
        }
        return jobPercent;
    }

    //获取Web打印出图模板列表
    @Override
    public List<TemplateEntity> getWebprintingLayoutsList() {
        List<TemplateEntity> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("type", "getWebprintingLayoutsList");
        RestResponse res = getServerToken(map);//获取Web打印出图模板列表
        if (res.getCode() == 200) {
            list = (List<TemplateEntity>) res.getData();
        }
        return list;
    }

    //获取Web打印出图模板列表
    private RestResponse supermapGetTemplateEntityList(Map<String, Object> map, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/webprinting/rest/webprinting/v1/layouts.rjson?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<String> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, String.class);
            JSONArray body = JSON.parseArray(JSON.parseObject(JSON.toJSONString(exchange)).getString("body"));
            if (body == null) {
                return null;
            }
            if (body.size() > 0) {
                List<TemplateEntity> templateEntityList = new ArrayList<>();
                for (int i = 0; i < body.size(); i++) {
                    String templateName = body.getJSONObject(i).getString("templateName");
                    Integer webMapFrameSizeX = body.getJSONObject(i).getJSONArray("webMapFrameSize").getInteger(0);
                    Integer webMapFrameSizeY = body.getJSONObject(i).getJSONArray("webMapFrameSize").getInteger(1);
                    TemplateEntity templateEntity = new TemplateEntity();
                    templateEntity.setTemplateName(templateName);
                    templateEntity.setWebMapFrameSizeX(webMapFrameSizeX);
                    templateEntity.setWebMapFrameSizeY(webMapFrameSizeY);
                    templateEntityList.add(templateEntity);
                }
                restResponse = RestResponse.succeed(templateEntityList);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //上传模板文件到超图模板目录
    @Override
    public RestResponse uploadTemplateFile(String attachId) {
        Map<String, Object> map = new HashMap<>();
        map.put("type", "uploadTemplateFile");
        String srcFile = null;
        //根据id和文件名获取真实的放在磁盘上的文件
        AttachmentInfoEntity attachmentInfoEntity = attachmentInfoService.getAttach(attachId);
        String attachPath = attachmentInfoEntity.getAttachPath();
        if (attachPath.endsWith(".ult")) {
            srcFile = attachmentInfoEntity.getFileDirId() + attachPath;
        }
        map.put("srcFile", srcFile);
        RestResponse res = getServerToken(map);//获取Web打印出图模板列表
        return res;
    }

    //上传模板文件到超图模板目录
    private RestResponse supermapPostTemplateFile(Map<String, Object> map, String serverToken) {
        RestResponse restResponse = null;
        try {
            //欲上传的源文件路径
            String srcFile = (String) map.get("srcFile");
//            srcFile = "D:/template/Administrative_Active_Fault-h1012/Administrative_Active_Fault-h1012_1710223152950.ult";
            if (PlatformObjectUtils.isEmpty(srcFile)) {
                System.out.println("无上传的源文件路径");
                return RestResponse.fail("无上传的源文件路径！");
            }
            File zipFile = null;
            if (srcFile.endsWith(".ult")) {
                String originFile = srcFile;
                String timeStamp = System.currentTimeMillis() + "";//时间戳，防止重名
                String tempFormat = "fxfzdzzh-t_";
                srcFile = srcFile.substring(0, srcFile.lastIndexOf(File.separator)) + "/" + tempFormat + timeStamp + ".ult";
                //复制文件，设置文件名，防止原文件名称超长
                FileUtil.copy(originFile, srcFile, true);
                //将.ult模板文件打包压缩包.zip
                //获取复制的文件
                File ultFile = new File(srcFile);
                //压缩文件路径
                srcFile = srcFile.substring(0, srcFile.lastIndexOf(".")) + ".zip";
                // 打成压缩包
                zipFile = new File(srcFile);
                FileOutputStream zipFos = new FileOutputStream(zipFile);
                ArchiveOutputStream archOut = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, zipFos);
                if (archOut instanceof ZipArchiveOutputStream) {
                    ZipArchiveOutputStream zos = (ZipArchiveOutputStream) archOut;
                    ZipArchiveEntry zipEntry = new ZipArchiveEntry(ultFile, ultFile.getName());
                    zos.putArchiveEntry(zipEntry);
                    zos.write(FileUtils.readFileToByteArray(ultFile));
                    zos.closeArchiveEntry();
                    zos.flush();
                    zos.close();
                }
                // 删除复制的文件
                if (ultFile.exists()) {
                    ultFile.delete();
                }
            } else {
                System.out.println("源文件不是超图Web打印模板");
                return RestResponse.fail("源文件不是超图Web打印模板！");
            }
//            String srcFile = "C:/Users/lenovo/Desktop/新建文件夹/fxfzaqbz-hf_1699350083999.zip";
            String fileName = srcFile.substring(srcFile.lastIndexOf("/") + 1);
            //欲上传的目标位置（位于服务器，相对于iServer应用目录/webapps/iserver/）
//            String destFile = "C:/Users/lenovo/Desktop/192/supermap-iserver-1111-22428-6922-windows-x64-deploy-usv3236/supermap-iserver-1111-22428-6922-windows-x64-deploy/webapps/iserver/templates/webprinting-layouts/fxfzaqbz-hf_1699350083888.zip";
//            String destFile = "/templates/webprinting-layouts/"+fileName;//相对路径
//            String destFile = "/usr/supermaprootnew/iserver/webapps/iserver/templates/webprinting-layouts/"+fileName;//绝对路径
//            String destFile = "/usr/supermaproot-111a/supermap-iserver-11.1.1a-linux-x64/supermap-iserver-11.1.1a-linux-x64/webapps/iserver/templates/webprinting-layouts/"+fileName;//绝对路径
//            String destFile = "/usr/supermaproot-333a/supermap-iserver-1111-23101-7024-linux-x64-deploy/webapps/iserver/templates/webprinting-layouts/";//绝对路径
            //查询字典--超图数据源工作空间文件路径
            DictItemEntity dte = dictItemRepository.findOneByDictItemCodeAndDictId("webprinting", "12");
            String destFile = dte.getDictItemName();//工作空间文件路径
            destFile += fileName;
            System.out.println(destFile);
            //是否覆盖
            boolean overwrite = true;
            //是否解压，上传的是zip文件，且unzip为true时，上传后iServer会将zip文件解压
            boolean unzip = true;

            String dataUrl = iServerHttp + "/iserver/manager/filemanager/uploadtasks.rjson?token=" + serverToken;
            dataUrl += "&toFile=" + destFile + "&overwrite=" + overwrite + "&unzip=" + unzip;

            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");

            //获取文件
            File file = new File(srcFile);
            if (!file.isFile()) {
                System.out.println("欲上传的源文件不存在。");
                return RestResponse.fail("欲上传的源文件不存在！");
            }
            //通过uploadtasks资源，创建一个uploadtask资源用于文件上传，并返回uploadtask资源的URL
            //创建时传入源文件的大小、目标路径、MD5，服务器端可据此判断磁盘空间是否充足，并在上传完成后进行MD5校验。
            long srcFileSize = file.length();
            String md5 = getMD5(file);
            String uploadtaskurl = getUploadTaskURL(dataUrl, srcFileSize, destFile, md5, serverToken);
            System.out.println("上传模板文件任务--" + uploadtaskurl);
            if (PlatformObjectUtils.isNotEmpty(uploadtaskurl)) {
                uploadtaskurl += ".json";
                uploadtaskurl = uploadtaskurl + "?toFile=" + destFile + "&overwrite=" + overwrite + "&unzip=" + unzip + "&token=" + serverToken;
                MultiValueMap<String, Object> bodyMap = new LinkedMultiValueMap<>();
                bodyMap.add("file", new FileSystemResource(file));
                HttpHeaders headers = new HttpHeaders();
                headers.setContentType(MediaType.MULTIPART_FORM_DATA);
                HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(bodyMap, headers);
                RestTemplate restTemplate = new RestTemplate();
                ResponseEntity<String> response = restTemplate.exchange(uploadtaskurl, HttpMethod.POST, requestEntity, String.class);
                JSONObject body = JSON.parseObject(JSON.parseObject(JSON.toJSONString(response)).getString("body"));
                System.out.println(body);
                String resultFileName = body.getString("fileName");//	上传文件或目录的名称。
//                String resultFilePath = body.getString("filePath");//文件上传后的目标文件或目录，用相对路径表示。相对路径的起算目录为 iServer 应用目录，如 Package 包中为%SuperMap iServer_HOME%\webapp\ iserver 目录 。
//                String fileSize = body.getString("fileSize");//	上传文件的大小，单位为字节。
//                String isDirectory = body.getString("isDirectory");//是否是目录，默认为 false。
                System.out.println("上传模板文件到超图模板目录成功" + resultFileName);
                // 删除压缩包
                if (zipFile.exists()) {
                    zipFile.delete();
                }
                /*//判断模板是否已在超图Web打印模板列表中
                boolean bool = false;
                while(bool==false){
                    Thread.sleep(10000);//10秒
                    //获取Web打印出图模板列表
                    List<TemplateEntity> templateEntityList = getWebprintingLayoutsList();
                    if(templateEntityList.size()>0){
                        for(TemplateEntity entity : templateEntityList){
                            if(resultFileName.equals(entity.getTemplateName())){
                                bool = true;
                                break;
                            }
                        }
                    }
                }
                System.out.println("成功发布模板文件到超图模板目录"+resultFileName);*/
                return RestResponse.succeed(resultFileName);
            } else {
                return RestResponse.fail("上传失败");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
    }

    //计算 file的MD5码
    private static String getMD5(File file) {
        String result = "";
        try {
            byte[] filebytes = FileUtils.readFileToByteArray(file);
            final char[] hexDigits = "0123456789abcdef".toCharArray();
            final byte[] md5 = MessageDigest.getInstance("MD5").digest(filebytes);
            final char[] md5Chars = new char[32];
            int i = 0;
            for (final byte b : md5) {
                md5Chars[i++] = hexDigits[(b >> 4) & 0xF];
                md5Chars[i++] = hexDigits[b & 0xF];
            }
            result = new String(md5Chars);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException nsae) {
            throw new IllegalStateException("No MD5 algorithm, unable to compute MD5");
        }
        return result;
    }

    //通过uploadtasks资源，创建一个uploadtask资源用于文件上传，并返回uploadtask资源的URL
    //创建时传入源文件的大小、目标路径、MD5，服务器端可据此判断磁盘空间是否充足，并在上传完成后进行MD5校验。
    public String getUploadTaskURL(String uploadtasksurl, long srcfileSize, String destFile, String md5, String token) throws ClientProtocolException, IOException {
        String result = "";
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(uploadtasksurl + "?token=" + token);
        //创建时传入源文件的大小、目标路径、MD5，服务器端可据此判断磁盘空间是否充足，并在上传完成后进行MD5校验。
        JSONObject entityStr = new JSONObject();
        try {
            entityStr.put("fileSize", srcfileSize);
            entityStr.put("filePath", destFile);
//            entityStr.put("path", destFile);
            entityStr.put("md5", md5);
        } catch (JSONException e1) {
            e1.printStackTrace();
        }
        StringEntity entity = new StringEntity(entityStr.toString(), "utf-8");
        entity.setContentType(new BasicHeader(org.apache.http.protocol.HTTP.CONTENT_TYPE, "application/json"));
        post.setEntity(entity);

        org.apache.http.HttpResponse response = client.execute(post);
        org.apache.http.HttpEntity responseEntity = response.getEntity();
        InputStream is = responseEntity.getContent();
        String responseEntityStr = new String(IOUtils.toByteArray(is), "utf-8");
        try {
            JSONObject body = JSON.parseObject(responseEntityStr);
            result = body.getString("newResourceLocation");
            System.out.println(result);
        } catch (JSONException e) {
            e.printStackTrace();
            result = null;
        }
        return result;
    }

    //刷新指定超图工作空间数据源数据集
    private RestResponse mapLayerWorkspaceReload(String smwuUrl, String datasource, String dataset, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/manager/workspaces/workspacereload.rjson?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //刷新指定数据源数据集时的参数设置，形式为{"workspaceConnectionInfo":"E:/MapData/fxfzdzzh/fxfzdzzh10/fxfzdzzh.smwu","isForce":true,"datasets":{"fxfzdzzh":["dzzh_slide_result_intensity"]}}
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("workspaceConnectionInfo", smwuUrl);
            jsonObject.put("isForce", true);
            //有数据集名则刷新指定数据集，无数据集名则刷新整个数据源
            if (PlatformObjectUtils.isNotEmpty(dataset)) {
                JSONObject datasets = new JSONObject();
                JSONArray datasetArray = new JSONArray();
                datasetArray.add(dataset);
                datasets.put(datasource, datasetArray);//数据源数据集名称
                jsonObject.put("datasets", datasets);
            }

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
            ResponseEntity<String> exchange1 = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, String.class);
//            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = JSON.parseObject(exchange1.getBody());
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            if (body.getBooleanValue("succeed")) {
                restResponse = RestResponse.succeed("刷新成功");
            } else {
                restResponse = RestResponse.fail("刷新失败");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //刷新指定超图工作空间数据源数据集
    @Override
    public boolean getWorkspaceReload(String dataset) {
        boolean bool = false;
        Map<String, Object> map = new HashMap<>();
        map.put("type", "WorkspaceReload");
        map.put("datasource", "fxfzdzzh");//数据源（数据库名）
        map.put("dataset", dataset);//数据集（表名）
        RestResponse restResponse1 = getServerToken(map);//刷新指定超图工作空间数据源数据集
        if (restResponse1.getCode() == 200) {
            //刷新成功
            bool = true;
        }

        return bool;
    }

    //刷新指定超图工作空间数据源数据集
    @Override
    public boolean getWorkspaceReload(String datasource, String dataset) {
        boolean bool = false;
        Map<String, Object> map = new HashMap<>();
        map.put("type", "WorkspaceReload");
        map.put("datasource", datasource);//数据源（数据库名）
        map.put("dataset", dataset);//数据集（表名）
        RestResponse restResponse1 = getServerToken(map);//刷新指定超图工作空间数据源数据集
        if (restResponse1.getCode() == 200) {
            //刷新成功
            bool = true;
        }

        return bool;
    }

    //获取超图服务token
    @Override
    public String getToken() {
        Map<String, Object> map = new HashMap<>();
        map.put("type", "token");
        RestResponse restResponse = getServerToken(map);
        String token = (String) restResponse.getData();

        return token;
    }

    //根据名称、类型批量删除数据集
    @Override
    public boolean batchDelByLayerType(String layerName, String layerType) {
        boolean bool = false;
        Map<String, Object> map = new HashMap<>();
        map.put("type", "batchDelByLayerType");
        map.put("layerName", layerName);//数据集（表名）
        map.put("layerType", layerType);//数据类型（栅格、面）
        RestResponse restResponse1 = getServerToken(map);//根据名称、类型批量删除数据集
        if (restResponse1.getCode() == 200) {
            //删除成功
            bool = true;
        }

        return bool;
    }

    //清除超图工作空间临时数据集
    @Override
    public void deleteWorkspaceDatasetTemp() {
        batchDelByLayerType("temp_*", "栅格");
        batchDelByLayerType("temp_*", "矢量");
    }

    //删除数据库空间表
    @Override
    public void dropGeometryTable(String tableName) {
        String sql = "select DropGeometryTable('" + tableName + "')";//空间表删除
        jdbcTemplate.execute(sql);
    }

    //查询数据库矢量数据到dzzhTifCount
    @Override
    public String dzzhVectorQuery(String queryType, String layerName, String sqlFilter, String timeStamp) {
        String resultLayerName = "temp_" + layerName + "_" + timeStamp;
        Map<String, Object> map0 = new HashMap<>();
        map0.put("type", "dzzhVectorQuery");
        map0.put("layerName", layerName);
        map0.put("resultLayerName", resultLayerName);
        map0.put("sqlFilter", sqlFilter);
        map0.put("queryType", queryType);
        RestResponse serverToken = getServerToken(map0);
        if (serverToken.getCode() != 200) {
            return null;
        }

        return resultLayerName;
    }

    //点数据集栅格克吕金插值分析提取等值面发布
    @Override
    public String dzzhVectorToGridPolygon(String pointLayerName, String queryType, String fieldName, String timeStamp) {
        //点数据集栅格克吕金插值分析提取等值面发布
        String gridLayerName = "temp_grid_" + timeStamp;
        String resultLayerName = "temp_" + fieldName + "_" + timeStamp;
        Map<String, Object> map = new HashMap<>();
        map.put("type", "dzzhVectorToGridPolygon");
        map.put("layerName", pointLayerName);//数据集（表名）
        map.put("queryType", queryType);//查询类型：软土震陷、标贯法砂土液化、液化指数法砂土液化
        map.put("fieldName", fieldName);//字段名称
        map.put("gridLayerName", gridLayerName);//栅格数据集名
        map.put("resultLayerName", resultLayerName);//结果数据集名
        RestResponse restResponse1 = getServerToken(map);
        if (restResponse1.getCode() == 200) {
            return resultLayerName;
        }

        return null;
    }

    //软土震陷点数据集栅格克吕金插值分析提取等值面发布
    @Override
    public RestResponse softSoilPointToGridPolygon(String dtId, String dtcvId) {
        if (PlatformObjectUtils.isEmpty(dtId) || PlatformObjectUtils.isEmpty(dtcvId)) {
            return RestResponse.fail("计算失败！");
        }
        String layerName = "dzzh_soft_soil_evaluate_result";
        String timeStamp = System.currentTimeMillis() + "";//时间戳，用于数据集名称后缀，防止重名
        String resultLayerName = "temp_" + layerName + "_" + timeStamp;
        //边界任务查询
        String sqlFilterClip = "dt_id='" + dtId + "'";
        //点数据集查询
        String sqlFilter = "dtcv_id='" + dtcvId + "'";
        Map<String, Object> map0 = new HashMap<>();
        map0.put("type", "dzzhVectorQuerySoftSoil");
        map0.put("layerName", "dzzh_task");//任务
        map0.put("resultLayerName", "temp_dzzh_task_" + timeStamp);
        map0.put("sqlFilter", sqlFilterClip);
        map0.put("layerName1", layerName);//软土震陷点数据
        map0.put("resultLayerName1", resultLayerName);
        map0.put("sqlFilter1", sqlFilter);
        RestResponse serverToken = getServerToken(map0);
        if (serverToken.getCode() != 200) {
            return RestResponse.fail("计算失败！");
        }

        //软土震陷根据烈度计算并保存等值面
        List<PolygonEvaluateResultVO> voList = new ArrayList<>();
        voList = countPolygonEvaluateResult(voList, dtcvId, "7", resultLayerName, timeStamp);
        if (voList == null) {
            return RestResponse.fail("计算失败！");
        }
        voList = countPolygonEvaluateResult(voList, dtcvId, "8", resultLayerName, timeStamp);
        if (voList == null) {
            return RestResponse.fail("计算失败！");
        }
        voList = countPolygonEvaluateResult(voList, dtcvId, "9", resultLayerName, timeStamp);
        if (voList == null) {
            return RestResponse.fail("计算失败！");
        }

        softSoilService.savePolygonEvaluateResult(voList);//保存等值面
        //刷新指定超图工作空间数据源数据集
        boolean bool = getWorkspaceReload("dzzh_soft_soil_polygon_evaluate_result");

        return RestResponse.succeed("计算成功！");
    }

    //软土震陷根据烈度计算并保存等值面
    @Override
    public List<PolygonEvaluateResultVO> countPolygonEvaluateResult(List<PolygonEvaluateResultVO> voList, String dtcvId, String intensity, String resultLayerName, String timeStamp) {
        String filedName = "is_soft" + intensity;
        String sql = "select " + filedName + " from dzzh_soft_soil_evaluate_result where dtcv_id='" + dtcvId + "' GROUP BY " + filedName;
        List<Integer> list = jdbcTemplate.queryForList(sql, Integer.class);
        if (list != null && list.size() > 0) {
            if (list.size() == 2) {
                //点数据集栅格克吕金插值分析提取等值面发布
                String tempResultLayerName = dzzhVectorToGridPolygon(resultLayerName, "软土震陷", filedName, timeStamp);
                if (PlatformObjectUtils.isNotEmpty(tempResultLayerName)) {
                    String sql1 = "select st_astext(st_union(smgeometry)) from " + tempResultLayerName + " where DMAXZVALUE<=0.5";
                    List<String> list1 = jdbcTemplate.queryForList(sql1, String.class);
                    if (list1 != null && list1.size() == 1) {
                        PolygonEvaluateResultVO vo = new PolygonEvaluateResultVO();
                        vo = new PolygonEvaluateResultVO();
                        vo.setDtcvId(dtcvId);
                        vo.setValue(0);//不震陷
                        vo.setGeom(list1.get(0));
                        vo.setType(intensity);
                        voList.add(vo);
                    }
                    String sql2 = "select st_astext(st_union(smgeometry)) from " + tempResultLayerName + " where dmaxzvalue>0.5";
                    List<String> list2 = jdbcTemplate.queryForList(sql2, String.class);
                    if (list2 != null && list2.size() == 1) {
                        PolygonEvaluateResultVO vo = new PolygonEvaluateResultVO();
                        vo.setDtcvId(dtcvId);
                        vo.setValue(1);//震陷
                        vo.setGeom(list2.get(0));
                        vo.setType(intensity);
                        voList.add(vo);
                    }
                    String sql3 = "select DropGeometryTable('" + tempResultLayerName + "')";//空间表删除
                    jdbcTemplate.execute(sql3);

                    return voList;
                }
            } else if (list.size() == 1) {//震陷、不震陷只存在1种
                String sql1 = "select st_extent(geom) from dzzh_soft_soil_evaluate_result where dtcv_id='" + dtcvId + "'";
                String boxExtent = jdbcTemplate.queryForObject(sql1, String.class);
                if (PlatformObjectUtils.isNotEmpty(boxExtent) && boxExtent.indexOf("BOX(") == 0) {
                    String box = boxExtent.replace("BOX(", "").replace(")", "");
                    String[] lonlatArr = box.split(",");
                    String[] minLonLat = lonlatArr[0].split(" ");
                    String[] maxLonLat = lonlatArr[1].split(" ");
                    String geom = "MULTIPOLYGON(((" + minLonLat[0] + " " + minLonLat[1] + ","
                            + minLonLat[0] + " " + maxLonLat[1] + ","
                            + maxLonLat[0] + " " + maxLonLat[1] + ","
                            + maxLonLat[0] + " " + minLonLat[1] + ","
                            + minLonLat[0] + " " + minLonLat[1] + ")))";
                    PolygonEvaluateResultVO vo = new PolygonEvaluateResultVO();
                    vo.setDtcvId(dtcvId);
                    vo.setValue(list.get(0));
                    vo.setGeom(geom);
                    vo.setType(intensity);
                    voList.add(vo);

                    return voList;
                }
            }
        }

        return null;
    }
}
